package chixing.day19.homework.work1;

import java.util.List;

public class Count2 {

    private Order order;

    public Count2() {
    }

    public Count2(Order order) {
        this.order = order;
    }

    //用于计算，商品价格
    //计算的逻辑 传入一个订单对象，
    //订单对象包含(用户对象、商品对象列表、原始总价)
    public void count2(Order order) {
        NewUserDiscount newUserDiscount = new NewUserDiscount();
        FestivalDiscount festivalDiscount = new FestivalDiscount();
        VIPDiscount vipDiscount = new VIPDiscount();
        System.out.println("原始价格为：" + order.getOriginPrice());
        double finalPrice = 0;
        /*
         * 判断是否是新用户
         * */
        List<Product> productList = order.getProductList();//用户的订单列表

        for (Product p : productList) {
            double temp = p.getProductPrice();

            if (order.getUser().isNewUser()) {
                temp = newUserDiscount.applyDiscount(temp, order.getUser(), p);
                System.out.println("应用优惠：NewUserDiscount，减 20.0，价格变为 " + temp);
            }

            if (p.isFestival()) {//该商品属于节日优惠
                temp = festivalDiscount.applyDiscount(temp, order.getUser(), p);
                System.out.println("应用优惠：FestivalDiscount，9 折，价格变为 " + temp);
            }

            if (order.getUser().isVip())
                temp = vipDiscount.applyDiscount(temp, order.getUser(), p);
            System.out.println("应用优惠：VIPDiscount，95 折，价格变为 " + temp);
            finalPrice += temp;
        }
        System.out.println("最终价格：" + finalPrice);

    }
}
